<template>
	<view class="container">
		<view class="detail">
			<view class="titleBox">
				<view class="title">{{ room.room_address }}</view>
				<view class="btn" @click="editInfo">编辑</view>
			</view>
			<view class="info">
				<view class="label">
					<view class="name">姓名：</view>
					<view class="value">{{ detail.customer_info.customer_name }}</view>
				</view>
				<view class="label">
					<view class="name">联系方式：</view>
					<view class="value">{{ detail.customer_info.customer_mobile }}</view>
				</view>
				<view class="label">
					<view class="name">证件号码：</view>
					<view class="value">{{ detail.customer_info.customer_idcard }}</view>
				</view>
				<view class="label">
					<view class="name">预定周期：</view>
					<view class="value">{{ detail.start_date }} 至 {{ detail.end_date }}</view>
				</view>
			</view>
		</view>
		<view class="detail">
			<view class="titleBox">
				<view class="title">备注</view>
				<view class="btn" @click="editDesc(detail)">编辑</view>
			</view>
			<view class="desc" v-if="detail.rent_remark">
				{{ detail.rent_remark }}
			</view>
		</view>
		<view class="botBtn">
			<button type="default" @click="deleteBook">退定</button>
			<button type="primary" @click="goRent">办理入住</button>
		</view>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			sn: null,
			detail: {},
			room: {}
		};
	},
	onLoad(e) {
		this.sn = e.sn;
	},
	onShow() {
		this.getDetail();
	},
	methods: {
		editInfo() {
			uni.navigateTo({
				url: '/pages/details/info/rent?sn=' + this.sn + '&type=book'
			});
		},
		editDesc(item) {
			uni.navigateTo({
				url: '/pages/details/desc?type=rent&sn=' + item.rent_sn + '&value=' + item.rent_remark
			});
		},
		goRent() {
			const info = this.detail.customer_info;
			uni.navigateTo({
				url:
					'/pages/add/rent?id=' +
					this.room.id +
					'&name=' +
					this.room.room_address +
					'&name=' +
					info.customer_name +
					'&mobile=' +
					info.customer_mobile +
					'&idcard=' +
					info.customer_idcard +
					'&start=' +
					this.detail.start_date +
					'&end=' +
					this.detail.end_date +
					'&sn=' +
					this.detail.rent_sn
			});
		},
		deleteBook() {
			const _this = this;
			uni.showModal({
				title: '提示',
				content: '确定取消预定？',
				success: function (res) {
					if (res.confirm) {
						api.deleteBook({ rent_sn: _this.sn }).then((data) => {
							if (data.data.is_success) {
								uni.showToast({
									title: '操作成功！'
								});
								setTimeout(() => {
									uni.hideToast();
									uni.navigateBack();
								}, 1000);
							}
						});
					}
				}
			});
		},
		getDetail() {
			api.rentDetail({ rent_sn: this.sn }).then((res) => {
				this.detail = res.data.info;
				this.getRoomDetail();
			});
		},
		getRoomDetail() {
			api.roomDetail({ room_id: this.detail.room_id }).then((res) => {
				this.room = res.data.info;
			});
		}
	}
};
</script>

<style lang="scss">
.detail {
	padding: 20rpx;
	margin-bottom: 20rpx;
	background: #fff;
	.titleBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		.title {
			font-size: 30rpx;
			font-weight: bold;
		}
		.btn {
			font-size: 28rpx;
			color: $uni-primary;
		}
	}
	.info {
		margin-top: 20rpx;
		.label {
			display: flex;
			font-size: 28rpx;
			line-height: 2;
			.name {
				width: 160rpx;
				text-align: right;
				color: $uni-secondary-color;
			}
			.value {
				flex: 1;
			}
		}
	}
	.desc {
		margin-top: 20rpx;
		background: $uni-bg-color;
		padding: 10rpx;
		font-size: 28rpx;
		line-height: 42rpx;
		color: $uni-base-color;
	}
}
.botBtn {
	margin-top: 100rpx;
	padding: 20rpx;
	display: flex;
	justify-content: space-around;
	padding-bottom: 100rpx;
	button {
		width: 300rpx;
	}
}
</style>
